#ifndef HAM_MODULE_H
#define HAM_MODULE_H

#include <QtWidgets/QMainWindow>
#include "../Common/Exception.h"
#include "../Common/Logging.h"
#include "PropertyList.h"
#include "../Widgets/WdgOptions.h"

namespace ham
{
	class System;

	class Module
		: public QMainWindow
	{
		Q_OBJECT

	public:
		virtual ~Module(void);
		
		// module identifying functions
		virtual QString	getModuleName() const = 0;
		virtual QString getDisplayName() const = 0;
		
		// initializing
		bool init(System*);
		virtual bool isInit() const;

		// module interfacing with main window
		virtual QList<QMenu*> getMenus(QWidget*) const;
		virtual QList<QPair<QString, QWidget*>> getMainWidgets(QWidget*);
		virtual QList<QPair<QString, QWidget*>> getToolbarWidgets(QWidget*);
		virtual WdgOptions* getOptionsWdg(QWidget*);

		// property management
		template <typename T>
		bool addProperty(const QString& name, const T& defaultVal);

		template <typename T>
		Property<T>* getProperty(const QString& name);
		
		bool loadProperties();
		bool saveProperties();

	protected:
		Module(QWidget*);

		virtual bool iInit() = 0;
		System* getSystem();
		
		PropertyList m_properties;
		
	private:
		bool m_isInit;
		System*	m_system;
	};
	
	template <typename T>
	bool Module::addProperty(const QString& name, const T& defaultVal)
	{
		return m_properties.addProperty(Property<T>(name, defaultVal));
	}
	
	template <typename T>
	Property<T>* Module::getProperty(const QString& name)
	{
		return m_properties.getProperty<T>(name);
	}
}

#endif // HAM_MODULE_H